package net.mudfox.helper;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import okhttp3.MediaType;

public class CommonHelper {
    private static final String ACTIVITY_TAG = "mudfox.tag";
    public static final MediaType JSON_TYPE = MediaType.parse("application/json;charset=utf-8");
    public static final String MIME_TYPE_TEXT = "text/plain";
    public static final String MIME_TYPE_HTML = "text/html";
    public static final String MIME_TYPE_URILIST = "text/uri-list";

    public static void debug(String message) {
        Log.d(ACTIVITY_TAG, message);
    }

    public static void setClipboardText(Activity activity, String label, String detail) {
        ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setPrimaryClip(ClipData.newPlainText(label, detail));
    }

    public static CharSequence getClipboardText(Activity activity) {
        ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        if (!cm.hasPrimaryClip())
            return "";
        else {
            return cm.getPrimaryClip().getItemAt(0).getText().toString();
        }
    }

    public static void showMessage(Activity activity, String message) {
        Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
    }
}
